﻿using SqlServerMaintenanceSolution.Models.Enums;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace SqlServerMaintenanceSolution.Models
{
    public class NetworkProtocol
    {

        //NAME	NETWORK LIBRARY
        //dbnmpntw	Named Pipes
        //dbmslpcn	Shared Memory (local machine connections only, might fail when moving to production...)
        //dbmssocn	Winsock TCP/IP
        //dbmsspxn	SPX/IPX
        //dbmsvinn	Banyan Vines
        //dbmsrpcn	Multi-Protocol (Windows RPC)
        //dbmsadsn	Apple Talk
        //dbmsgnet	VIA

        public Protocol Protocol { get; set; }
        public String Name { get; set; }

        public NetworkProtocol()
        { }

         

        public NetworkProtocol(Protocol protocol)
        {
            this.Protocol = protocol;
            switch (protocol)
            {
                case Protocol.SharedMemory:                
                    this.Name = "dbmslpcn";
                    break;
                case Protocol.NamedPipes:                
                    this.Name = "dbnmpntw";
                    break;
                case Protocol.TCP_IP:                
                    this.Name = "dbmssocn";
                    break;
                default:
                    this.Name = "dbmssocn";
                    break;
            }
        }

        public NetworkProtocol(string protocol)
        {
             
            switch (protocol)
            {
                case "SharedMemory":
                    this.Protocol = Protocol.SharedMemory;
                    this.Name = "dbmslpcn";
                    break;
                case "NamedPipes":
                    this.Protocol = Protocol.NamedPipes;
                    this.Name = "dbnmpntw";
                    break;
                case "TCP_IP":
                    this.Protocol = Protocol.TCP_IP;
                    this.Name = "dbmssocn";
                    break;
                default:
                    this.Protocol = Protocol.TCP_IP;
                    this.Name = "dbmssocn";
                    break;
            }
        }

        public static IEnumerable<NetworkProtocol> GetNetworkProtocols()
        {
            var protocols = new List<NetworkProtocol>();

            foreach (Protocol protocol in Enum.GetValues(typeof(Protocol)))
            {
                protocols.Add(new NetworkProtocol(protocol));
            }

            return protocols;
        }
    }
}
